﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using diploma.core.data;
using diploma.core.localize;

namespace diploma.core.GUI
{
    public abstract class DiplomaForm : Form, ILocalizable
    {
        protected Dictionary<DataObjectTypes, DataList<diploma.core.data.IDataObject>> dataObjectsCollections;
        protected AbstractLocalizator localizator;
        protected System.ComponentModel.IContainer components = null;
        protected Form parent;

        

        public DiplomaForm(Form _parent, AbstractLocalizator _localizator , params DataList<diploma.core.data.IDataObject>[] _dataObjectsCollections)
            : base()
        {
            InitializeComponent();
            localizator = _localizator;
            this.Hide();
            dataObjectsCollections = new Dictionary<DataObjectTypes, DataList<diploma.core.data.IDataObject>>();
            fillToolBarElements();
            fillMainMenuElements();
            fillStatusBarElements();
            parent = _parent;
            foreach (DataList<diploma.core.data.IDataObject> _dataObjects in _dataObjectsCollections)
            {
                dataObjectsCollections.Add(_dataObjects.ObjectsType, _dataObjects);
            }
            Localize();
        }

        protected virtual void fillToolBarElements()
        {
            toolBarElements = new List<ToolStripItem>();
        }
        protected virtual void fillMainMenuElements()
        {
            mainMenuElements = new List<ToolStripItem>();
        }
        protected virtual void fillStatusBarElements()
        {
            statusBarElements = new List<ToolStripItem>();
        }

        protected List<ToolStripItem> toolBarElements;
        public ToolStripItem[] ToolBarElements
        {
            get
            {
                return toolBarElements.ToArray();
            }
        }

        protected List<ToolStripItem> mainMenuElements;
        public ToolStripItem[] MainMenuElements
        {
            get
            {
                return mainMenuElements.ToArray();
            }
        }

        protected List<ToolStripItem> statusBarElements;
        public ToolStripItem[] StatusBarElements
        {
            get
            {
                return statusBarElements.ToArray();
            }
        }

        protected virtual void InitializeComponent()
        {
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Closed);
        }

        protected override void Dispose(bool disposing)
        {
            this.Hide();
            RefreshToolStrips();
        }

        protected void Closed(object sender, FormClosedEventArgs e)
        {
            this.Visible = false;
           // RefreshToolStrips();          
        }

        protected virtual void RefreshToolStrips()
        {
            foreach (ToolStripMenuItem m in mainMenuElements)
            {
                if (m.Checked) m.Checked = false;
            }
        }

        public virtual void DisposeBase(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region ILocalizable Members

        public abstract void Localize();

        #endregion
    }
}
